/*
Creates subset of full RAIS data with spells in our subset of establishments 
		// input: rais_20102017; estabtreat_forRAIS_deid; quitsnewhires
		// output: quitsnewhires_full

*/

cap log close
cap log using "$logs/create_fullworkers_sample", replace 

*****************
* Create dataset of all workers 
*****************

use "$files/rais/BR/rais_20102017.dta", clear


*****************
* Merge with treatment variable at the worker level
* Only keep workers who were at a treated or control employer at a given point in time
*****************

merge m:1 fakeid_estab using "$files/estabtreat_forRAIS_deid.dta"
keep if _merge==3
drop _merge

preserve
	use "$files/quitsnewhires.dta", clear
	keep fakeid_estab treat ind_mode municipality_mode bl_singest bl_bothFM bl_signing bl_covered
	duplicates drop 
	tempfile temp
	save `temp'
restore

cap drop treat 
cap drop ind_mode 
cap drop municipality_mode 
cap drop bl_singest 
cap drop bl_bothFM 
cap drop bl_signing 
cap drop bl_covered
merge m:1 fakeid_estab using `temp'
keep if _merge==3
drop _merge


sort fakeid_worker year, stable
save "$files/quitsnewhires_full.dta", replace


cap log close
